package com.study.www.demo.config;

import com.study.www.demo.Application;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器
 *
 * @author : Administrator.zhuyanpeng
 * @date : 2019/11/15 - 16:46
 */
@Slf4j
@Component
public class Demo1Interceptor implements HandlerInterceptor {

    public Demo1Interceptor() {
        log.warn("Interceptor 的 constructor ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.warn("Interceptor 的 preHandle ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.warn("Interceptor 的 postHandle ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.warn("Interceptor 的 afterCompletion ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
    }
}
